package com.example.doer.reading.AppActivities;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.ab.fragment.AbFragment;
import com.example.doer.reading.R;

import static com.ab.util.AbToastUtil.showToast;


public class LoginFragment extends AbFragment {

    private Button btnLogin;
    private Button btnRegister;
    private MainActivity mainActivity;

    private String UserName;
    private String UserPass;
    public LoginFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mainActivity= (MainActivity) getActivity();
        View view = inflater.inflate(R.layout.fragment_login,null);

        final EditText et_Name = (EditText)view.findViewById(R.id.et_usrName);
        final EditText et_Pass = (EditText)view.findViewById(R.id.et_usrPass);


        btnLogin = (Button)view.findViewById(R.id.btnLogin);
        btnRegister = (Button)view.findViewById(R.id.btnRegister);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String InputName = et_Name.getText().toString();
                final String InputPass = et_Pass.getText().toString();
              if(InputName.equals(LoginFragment.this.getUserNameFromDB())&InputPass.equals(LoginFragment.this.getUserPassFromDB()))
              {
                  FragmentManager fm = getFragmentManager();
                  FragmentTransaction ft = fm.beginTransaction();
                  //ft.replace(R.id.realtabcontent,mainActivity.getFragmentList().get(3));
                  //ft.commit();
                  ft.hide(LoginFragment.this).commit();
                  fm.beginTransaction().show(mainActivity.getFragmentList().get(3)).commit();
                  getActivity().findViewById(R.id.main_bottom).setVisibility(View.VISIBLE);
              }
              else
              {
                  showToast(getActivity(),"invalid PassWord or UserName");
              }
            }
        });

        return view;
    }

    public String getUserNameFromDB(){
        return "WBL";
    }
    public String getUserPassFromDB(){
        return "123456";
    }






}
